package com.journal.book.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.journal.common.annotation.Log;
import com.journal.common.core.controller.BaseController;
import com.journal.common.core.domain.AjaxResult;
import com.journal.common.enums.BusinessType;
import com.journal.book.domain.BookShelfInfo;
import com.journal.book.service.IBookShelfInfoService;
import com.journal.common.utils.poi.ExcelUtil;
import com.journal.common.core.page.TableDataInfo;

/**
 * bookController
 * 
 * @author ruoyi
 * @date 2025-11-08
 */
@RestController
@RequestMapping("/book/book")
public class BookShelfInfoController extends BaseController
{
    @Autowired
    private IBookShelfInfoService bookShelfInfoService;

    /**
     * 查询book列表
     */
    @PreAuthorize("@ss.hasPermi('book:book:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookShelfInfo bookShelfInfo)
    {
        startPage();
        List<BookShelfInfo> list = bookShelfInfoService.selectBookShelfInfoList(bookShelfInfo);
        return getDataTable(list);
    }

    /**
     * 导出book列表
     */
    @PreAuthorize("@ss.hasPermi('book:book:export')")
    @Log(title = "book", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookShelfInfo bookShelfInfo)
    {
        List<BookShelfInfo> list = bookShelfInfoService.selectBookShelfInfoList(bookShelfInfo);
        ExcelUtil<BookShelfInfo> util = new ExcelUtil<BookShelfInfo>(BookShelfInfo.class);
        util.exportExcel(response, list, "book数据");
    }

    /**
     * 获取book详细信息
     */
    @PreAuthorize("@ss.hasPermi('book:book:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bookShelfInfoService.selectBookShelfInfoById(id));
    }

    /**
     * 新增book
     */
    @PreAuthorize("@ss.hasPermi('book:book:add')")
    @Log(title = "book", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookShelfInfo bookShelfInfo)
    {
        return toAjax(bookShelfInfoService.insertBookShelfInfo(bookShelfInfo));
    }

    /**
     * 修改book
     */
    @PreAuthorize("@ss.hasPermi('book:book:edit')")
    @Log(title = "book", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookShelfInfo bookShelfInfo)
    {
        return toAjax(bookShelfInfoService.updateBookShelfInfo(bookShelfInfo));
    }

    /**
     * 删除book
     */
    @PreAuthorize("@ss.hasPermi('book:book:remove')")
    @Log(title = "book", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookShelfInfoService.deleteBookShelfInfoByIds(ids));
    }
}
